<script>

import * as echarts from 'echarts';
export default {
  name: 'MonthTs',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data4', {

      }).then(res =>{
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          let data3 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            let list = res.data.data[i].column1.split("-");
            data1.push(
                list[1] + list[2]
            );
            data2.push(
                res.data.data[i].column2.replace("℃", "")
            );
            data3.push(
                res.data.data[i].column3.replace("℃", "")
            );
          }
          this.init(data1, data2, data3);
        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2, data3) {
      var chartDom = document.getElementById('main2');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '贵阳历史高低温'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {},
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: { readOnly: false },
            magicType: { type: ['line', 'bar'] },
            restore: {},
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: data1
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: '{value} °C'
          }
        },
        series: [
          {
            name: '高温',
            type: 'line',
            data: data2,
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              data: [{ type: 'average', name: 'Avg' }]
            }
          },
          {
            name: '低温',
            type: 'line',
            data: data3,
            markPoint: {
              data: [{ name: '最低', value: -2, xAxis: 1, yAxis: -1.5 }]
            },
            markLine: {
              data: [
                { type: 'average', name: 'Avg' },
                [
                  {
                    symbol: 'none',
                    x: '90%',
                    yAxis: 'max'
                  },
                  {
                    symbol: 'circle',
                    label: {
                      position: 'start',
                      formatter: 'Max'
                    },
                    type: 'max',
                    name: '高点'
                  }
                ]
              ]
            }
          }
        ]
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main2"></div>
</template>

<style scoped>
#main2 {
  width: 100%;
  height: 100%;
}
</style>